#include "GlobalThresholdBinarisation.hpp"

/** @todo remove imports */
#include <iostream>

GlobalThresholdBinarisation::GlobalThresholdBinarisation(const girl::tools::Image &image, int threshold)
    :_image(image),
    _threshold(threshold),
    _toger(image.width(),image.height()),
    sameRegion(new ThresholdSameRegion(_image,_threshold))
{
    _toger.splitRegion(1,*sameRegion,_regions);

    girl::regionDeque::iterator it = _regions.begin();
    girl::regionDeque::iterator itEnd = _regions.end();

    std::cout << " ICI "  << std::endl;
    for(; it != itEnd; ++it)
    {
        girl::point p = _toger.anyPoint(*it);
        if(_image.getPixel(p.x(),p.y()).a() <= _threshold)
            _underThdRegions.push_back(*it);
    }
    std::cout << " ICI 2 "  << std::endl;

}

GlobalThresholdBinarisation::~GlobalThresholdBinarisation()
{
    delete sameRegion;
}
